﻿using RayDen.Library.Core.Primitives;
using RayDen.RayEngine.Core;
using RayDen.RayEngine.Core.Devices;
using RayDen.RayEngine.Core.Interface;
using RayDen.RayEngine.Core.Threads;
using RayDen.RayEngine.Managers;
using RayDen.RayEngine.Samplers;

namespace RayDen.RayEngine.Engines.SpectralPT
{
    public class SpectralPathTracerEngine : BaseRenderingEngine
    {
        public SpectralPathTracerEngine(RayEngineScene scene) : base(scene)
        {
            GlobalConfiguration.Instance.SpectralRendering = true;
            RgbSpectrum.Gamma = true;
        }

        public override RenderThread CreateRenderThread(int threadIndex, IntersectionEngine intersectionDevice, RayEngineScene scene,
                                                        IImageFilm film, IFrameManager manager, SamplingContext samplingContext)
        {
            return new DeviceRenderThread<PathBuffer<UnidirectionalSpectralPathSampler>>(threadIndex, intersectionDevice, scene,
                                                                    LowLatencySampling, film, samplingContext, manager);
        }

        public override ISampler CreateSampler(int width, int height, int maxPathDepth, int threadIndex, int screenStartLine, int windowHeight)
        {
            return SamplerFactory.Instance.CreateSampler(width, height, maxPathDepth, screenStartLine, LowLatencySampling,
                                                  threadIndex, windowHeight);
        }

        public override IImageFilm CreateFilm(int width, int height)
        {
            return new ImageFilm<UnidirectionalSpectralPathSampler>(width, height);
        }
    }
}